/**
 *
 * Copyright (c) 2011, Preecha A. All rights reserved.
 *
 * This is proprietary source code of Preecha A.
 *
 */

/**
 * 
 */
package com.nk.system.service.impl;

/**
 * @author Preecha
 *
 */

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.nk.system.common.search.Search;
import com.nk.system.common.search.SearchResult;
import com.nk.system.dao.GenericDAO;
import com.nk.system.service.GenericService;


public abstract class GenericServiceImpl<T, ID extends Serializable, DAO extends GenericDAO<T, ID>> implements GenericService<T, ID> {
	protected DAO dao;

	public GenericServiceImpl() {
	}
	
	public GenericServiceImpl(DAO dao) {
		this.dao = dao;
	}

	@Transactional
	public int count(Search search) {
		return dao.count(search);
	}

	@Override
	@Transactional
	public boolean deleteById(ID id) {
		return dao.deleteById(id);
	}

	@Override
	@Transactional
	public void deleteByIds(ID... ids) {
		dao.deleteByIds(ids);
	}

	@Override
	@Transactional
	public T save(T entity) {

		return dao.save(entity);
	}

	@Override
	@Transactional
	public T[] save(T... entities) {

		return dao.save(entities);
	}

	@Transactional
	public T saveOrUpdate(T entity) {

		return dao.saveOrUpdate(entity);
	}

	@Override
	@Transactional
	public T update(T entity) {

		return dao.update(entity);
	}

	@Transactional
	public <RT> List<RT> search(Search search) {
		return dao.search(search);
	}

	@Transactional
	public <RT> SearchResult<RT> searchAndCount(Search search) {
		return dao.searchAndCount(search);
	}

	@Transactional
	public <RT> RT searchUnique(Search search) {
		return dao.searchUnique(search);
	}

	@Override
	@Transactional
	public List<T> findAll() {
		return dao.findAll();
	}

	@Override
	public T findById(ID id) {
		return dao.findById(id, true);
	}

}
